package top.lyjwn.todo.security;


import com.alibaba.fastjson2.JSONObject;

import java.time.LocalDateTime;

public abstract class Login {

    private String privateKey;

    public String getPrivateKey() {
        return privateKey;
    }

    public static Login instance(JSONObject jsonObject) {
        Login login = new Login() {
            @Override
            public String getAccount() {
                return jsonObject.getString("account");
            }

            @Override
            public Integer getType() {
                return jsonObject.getInteger("type");
            }

            @Override
            public String getPlatform() {
                return jsonObject.getString("Platform");
            }

            @Override
            public String getOpenid() {
                return jsonObject.getString("openid");
            }

            @Override
            public String getUnionid() {
                return jsonObject.getString("type");
            }

            @Override
            public String getUserId() {
                return jsonObject.getString("userId");
            }

            @Override
            public LocalDateTime getLoginTime() {
                String loginTime = jsonObject.getString("loginTime");
                LocalDateTime parse = LocalDateTime.parse(loginTime);
                return parse;
            }
        };
        login.setPrivateKey(jsonObject.getString("privateKey"));
        return login;
    }

    public void setPrivateKey(String privateKey) {
        this.privateKey = privateKey;
    }

    public abstract String getAccount();

    public abstract Integer getType();

    public abstract String getPlatform();

    public abstract String getOpenid();

    public abstract String getUnionid();

    public abstract String getUserId();

    public abstract LocalDateTime getLoginTime();


}
